#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;

signed  main() {
    int n, k;
    cin >> n >> k;
    vector<int> A(n);
    
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }

    vector<int> pre(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        pre[i] = pre[i - 1] + A[i - 1];
    }

    vector<int> suf(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        suf[i] = suf[i - 1] + A[n - i];
    }
    
    int sum = 0;

    for (int x = 0; x <= min(k, n); x++) {
        if (x <= n && (k - x) <= n) {
            int res = pre[n - (k - x)] - pre[x];
            sum = max(sum , res);
        }
    }
    
    cout << sum << endl;
    return 0;
}
